package com.pp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pp.common.pojo.District;
import com.pp.mapper.DistrictMapper;
import com.pp.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DistrictServiceImpl implements DistrictService {

    @Autowired
    private DistrictMapper districtMapper;

    @Override
    public List<District> getByParentCode(String parentCode) {
        QueryWrapper<District> queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent_code", parentCode)
                    .orderByAsc("parent_code");
        return districtMapper.selectList(queryWrapper);
    }

    @Override
    public District getByCode(String code) {
        QueryWrapper<District> queryWrapper = new QueryWrapper();
        queryWrapper.eq("code", code)
                .orderByAsc("code");
        return districtMapper.selectOne(queryWrapper);
    }
}

